package com.zretc.service.impl;

import com.zretc.dao.AccountMapper;
import com.zretc.entity.Account;
import com.zretc.service.AccountService;
import com.zretc.util.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AccountServiceImpl implements AccountService {

    @Autowired
    private AccountMapper accountMapper;

    @Override
    public Account login(String accountName, String password) {
        password=MD5Util.getMd5(password);
        return accountMapper.findByNameAndPassword(accountName, password);
    }

    @Override
    public boolean register(Account account) {
        account.setPassword(MD5Util.getMd5(account.getPassword()));
        return accountMapper.add(account)!=0?true:false;
    }

    @Override
    public Account isExistByName(String accountName) {

        return accountMapper.findByName(accountName);
    }

    @Override
    public Account getAccountByName(String accountName) {
        return accountMapper.findAccountByName(accountName);
    }

    @Override
    public int updataPasswordByAccountName(String accountName, String newPassword) {
        Account account = accountMapper.findAccountByName(accountName);
       String password=MD5Util.getMd5(newPassword);
        account.setPassword(password);
        int i = accountMapper.updataPasswordByAccountName(account);
        return i;
    }

    /*@Override
    public int updataPasswordByAccountName(String accountName, String password) {

        int i = accountMapper.updataPasswordByAccountName(accountName,password);
        return i;
    }*/
}
